#include "MemoryCache.h"

#include <algorithm>

#include "WordReport.h"

#include <spdlog/spdlog.h>

int MemoryCache::AddWord(const std::string& word) {
    if(!IsValidWord(word)){
        return ADD_ERROR_WRONG;
    }

    for (auto& w : m_words) {
        if (w == word) {
            return ADD_ERROR_DUPLICATED;
        }
    }
    SPDLOG_INFO("add word:{}", word);
    m_words.push_back(word);

    return ADD_SUCCESS;
}

bool MemoryCache::IsValidWord(const std::string& word) {
    //TODO check if word is valid.

    return true;
}

void MemoryCache::Report() {
    m_report->Print(m_words);
}

std::vector<std::string> MemoryCache::GetWords() {
    return m_words;
}